package com.core.controller.User;

import com.core.pojo.Result.Result;
import com.core.pojo.User.dto.UserLoginReqDTO;
import com.core.pojo.User.entity.User;
import com.core.service.User.UserLoginService;
import com.core.toolkit.jwt.JwtUtil;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@Tag(name = "用户登录模块")
@RequiredArgsConstructor
public class UserLoginController {

    private final JwtUtil jwtUtil;
    private final UserLoginService userLoginService;


    @Operation(summary = "用户登录", description = "用户登录")
    @PostMapping("/login")
    public Result<String> login(@RequestBody UserLoginReqDTO request) {
        return userLoginService.loginAuthenticate(request);
    }

    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public Result<User> register(@RequestBody User request) {
        return userLoginService.register(request);
    }

    @Operation(summary = "用户退出登录")
    @GetMapping("/logout")
    public Result<Void> logout(@RequestParam(required = false) String accessToken) {
        userLoginService.logout(accessToken);
        return Result.success();
    }


}
